import { Scene } from 'phaser';
import { EventBus } from '@/EventBus';
import { polygon, oval, bullet } from '../enums';

export class Boot extends Scene {

    constructor() {
        super('Boot');
    }

    preload() {
        // console.log('Boot-preload')

        this.load.setPath('assets');
        this.load.image('townImg', 'town.png')
        this.load.image('diamondImg', 'diamond.png')
        this.load.tilemapTiledJSON('backgroundMap', 'background.json')

        const myGraphics = this.add.graphics()
        myGraphics.fillStyle(0x0d0c0c)
        myGraphics.fillCircle(20, 20, 20)
        myGraphics.generateTexture(oval.circle, 40, 40)
        myGraphics.clear()

        myGraphics.beginPath()
        myGraphics.fillStyle(0xffffff)
        myGraphics.moveTo(20, 0)
        myGraphics.lineTo(0, 40)
        myGraphics.lineTo(40, 40)
        myGraphics.closePath()
        myGraphics.fill()
        myGraphics.generateTexture(polygon.three, 40, 40)
        myGraphics.clear()

        myGraphics.beginPath()
        myGraphics.fillStyle(0xffffff)
        myGraphics.moveTo(0, 0)
        myGraphics.lineTo(40, 0)
        myGraphics.lineTo(40, 40)
        myGraphics.lineTo(0, 40)
        myGraphics.closePath()
        myGraphics.fill()
        myGraphics.generateTexture(polygon.four, 40, 40)
        myGraphics.clear()

        myGraphics.beginPath()
        myGraphics.fillStyle(0xffffff)
        myGraphics.moveTo(0, 0)
        myGraphics.lineTo(10, 0)
        myGraphics.lineTo(10, 10)
        myGraphics.lineTo(0, 10)
        myGraphics.closePath()
        myGraphics.fill()
        myGraphics.generateTexture(bullet.fourBullet, 10, 10)
        myGraphics.clear()

        myGraphics.destroy()
    }

    create() {
        // console.log('Boot-create')
        EventBus.on('toMainScene', () => {
            // console.log('前往MainScene')
            this.scene.start('MainScene')
        })

    }
}
